package com.neusoft.elm.service.impl;

import com.neusoft.elm.dao.CartDao;
import com.neusoft.elm.dao.impl.CartDaoImpl;
import com.neusoft.elm.po.Cart;
import com.neusoft.elm.service.CartService;
import com.neusoft.elm.util.DBUtil;

import java.util.List;

public class CartServiceImpl implements CartService {
    CartDao cartDao=new CartDaoImpl();
    @Override
    public List<Cart> listCart(Cart cart) throws Exception {
        try {
            DBUtil.getConnection();
            List<Cart> list = cartDao.listCart(cart);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            DBUtil.close();
        }
    }

    @Override
    public int saveCart(Cart cart) throws Exception {
        try {
            DBUtil.getConnection();
            int i = cartDao.saveCart(cart);
            return i;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            DBUtil.close();
        }
    }

    @Override
    public int removeCart(Cart cart) throws Exception {
        try {
            DBUtil.getConnection();
            int i = cartDao.removeCart(cart);
            return i;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            DBUtil.close();
        }
    }

    @Override
    public int updateCart(Cart cart) throws Exception {
        try {
            DBUtil.getConnection();
            int i = cartDao.updateCart(cart);
            return i;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            DBUtil.close();
        }
    }
}
